<template>
  <div>
     <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row>
        <el-col :span="8">
         <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getProductList">
           <el-button slot="append" icon="el-icon-search" @click="getProductList"></el-button>
         </el-input>
        </el-col>
      </el-row>
      <!-- 订单列表 -->
      <el-table :data="ordingList" stripe>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="订单编号" prop="ordId"></el-table-column>
        <el-table-column label="订单价格" prop="price"></el-table-column>
        <el-table-column label="是否付款" prop="is_paid">
          <template slot-scope="scope">
             <el-tag v-if="scope.row.is_paid" type="success">已付款</el-tag>
             <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send">
          <template slot-scope="scope">
            <i class="el-icon-success" v-if="scope.row.deleted === false" style="color:lightgreen"></i>
            <i class="el-icon-error" v-else style="color:#666;margin-left:20px;"></i>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" prop="created_time">
          <template slot-scope="scope">
          {{ scope.row.created_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-tooltip  effect="dark" content="修改地址" placement="top" :enterable="false">
            <el-button v-model="scope.row._id" type="primary" icon="el-icon-edit" size="mini" @click="editlocal(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip  effect="dark" content="物流信息" placement="top" :enterable="false">
            <el-button type="success" icon="el-icon-location" size="mini" @click="openProcess"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
        <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="location"
      width="40%"
       @close="clearAddress">
      <!-- 添加信息 -->
      <el-form :model="addressForm" :rules="addressRules" ref="addressFormRef" label-width="100px">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :props="addressSelect"
            :options="cityData"
            clearable
            expand-trigger="hover"
          >
          </el-cascader>
        </el-form-item>
          <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部按钮 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="location = false">取 消</el-button>
        <el-button type="primary" @click="location = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度 -->
    <el-dialog
      title="物流进度"
      :visible.sync="process"
      width="40%"
      >
      <!-- 添加信息 -->
      <el-timeline :reverse="reverse">
        <el-timeline-item
        v-for="(activity, index) in proecss[0].Traces"
        :key="index"
        :timestamp="activity.AcceptTime">
        {{activity.AcceptStation}}
        </el-timeline-item>
      </el-timeline>
      <!-- 底部按钮 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="process = false">取 消</el-button>
        <el-button type="primary" @click="process = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import cityData from './city_code.json'
import proecss from './proecss.json'

export default {
  data () {
    return {
      queryInfo: {
        query: ''
      },
      ordingList: [],
      location: false,
      addressForm: {
        address1: [],
        address2: ''
      },
      addressRules: {
        address1: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入地址', trigger: 'blur' }
        ]
      },
      cityData,
      addressSelect: {
        value: 'name',
        label: 'name',
        children: 'children'
      },
      proecss,
      process: false,
      reverse: true
    }
  },
  methods: {
    async getProductList () {
      const res = await this.$http.get('/ording')
      this.ordingList = res.data
    },
    editlocal (e) {
      console.log(e)
      console.log(this.proecss)
      this.location = true
    },
    clearAddress () {
      this.$refs.addressFormRef.resetFields()
    },
    openProcess () {
      this.process = true
    }
  },
  created () {
    this.getProductList()
  }
}
</script>
<style lang="less" scoped></style>
